function t(t, a, e) {
    return a in t ? Object.defineProperty(t, a, {
        value: e,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : t[a] = e, t;
}

var a = require("../../utils/api.js"), e = getApp();

Page({
    data: t({
        status: 0,
        stopClick: void 0,
        stopcancelClick: void 0,
        carnum: "",
        showLoding: !0,
        showlodingmore: {
            showMore: !0,
            noMore: !1
        },
        showSuccesstipInfo: {
            showSuccesstip: !0,
            title: "已加入购物车",
            type: !0
        },
        showCount: 10,
        mid: !1,
        default_small_img: e.globalData.default_small_img,
        playBtn: "/images/playvideo.png",
        maxpage: 2
    }, "showLoding", !1),
    onLoad: function(t) {
        var o = t.id, s = t.allnum;
        console.log(o);
        var i = this;
        wx.setNavigationBarColor({
            frontColor: wx.getStorageSync("basic").topcolor,
            backgroundColor: wx.getStorageSync("basic").topbg
        }), i.setData({
            id: o,
            allnum: s
        }), a.getorderDetails({
            id: o
        }).then(function(t) {
            console.log(t);
            for (var o = "", s = 0; s < t.data.item.length; s++) s == t.data.item.length - 1 ? o += t.data.item[s].oss_gid : o += t.data.item[s].oss_gid + ",";
            var n = {
                openid: e.globalData.openid,
                page: 1,
                gid: o
            };
            console.log(n), a.GoodsInfoRecommend(n).then(function(t) {
                console.log(t), i.setData({
                    suggestGoods: t.data.data,
                    othergoods: t.data,
                    showLoding: !0
                });
            }), i.setData({
                "item.name": t.data.item[0].oss_buy_name,
                "item.phone": t.data.item[0].oss_buy_phone,
                price: t.data.go_real_price,
                time: t.data.date,
                code: t.data.go_code,
                info: t.data.item,
                data: t.data,
                gids: o,
                page: 1
            }), console.log(i.data.suggestGoods);
        }), a.getCartNum({
            openid: e.globalData.openid
        }).then(function(t) {
            console.log(t.data), i.setData({
                carnum: t.data
            });
        });
    },
    onShow: function() {
        this.setData({
            stopClick: !1,
            stopcancelClick: !1
        });
    },
    callDialog: function(t) {
        var o = this;
        o.setData({
            stopcancelClick: !0
        }), console.log(o.data.stopcancelClick);
        var s = t.currentTarget.dataset.orderid;
        a.delOrder({
            openid: e.globalData.openid,
            id: s
        }).then(function(t) {
            0 == t.errno ? (wx.showToast({
                title: "取消成功",
                icon: "success",
                duration: 2e3
            }), wx.navigateTo({
                url: "../order/orderList?id=0"
            })) : wx.showToast({
                title: "取消失败",
                icon: "none",
                duration: 2e3
            });
        });
    },
    repeat: function() {
        wx.showToast({
            title: "请30秒后再次点击付款",
            icon: "none",
            duration: 2e3,
            mask: !0
        });
    },
    btnPay: function(t) {
        var o = this;
        o.setData({
            repeatClick: !0,
            showLoding: !1
        }), o.data.repeatClick && setTimeout(function() {
            o.setData({
                repeatClick: !1
            });
        }, 3e4);
        var s = t.currentTarget.dataset.orderid;
        a.getorder_pay({
            openid: e.globalData.openid,
            id: s
        }).then(function(t) {
            console.log(t), o.setData({
                showLoding: !0
            }), wx.requestPayment({
                timeStamp: t.data.timeStamp,
                nonceStr: t.data.nonceStr,
                package: t.data.package,
                signType: "RSA",
                paySign: t.data.paySign,
                success: function(s) {
                    wx.showToast({
                        title: "支付成功",
                        icon: "loading",
                        mask: !0,
                        duration: 2e3
                    }), console.log(t.data.gid), a.payment({
                        cid: t.data.id,
                        gid: t.data.gid,
                        openid: e.globalData.openid
                    }).then(function(t) {
                        0 == t.errno ? a.getorderDetails({
                            id: o.data.id
                        }).then(function(t) {
                            console.log(t.data), o.setData({
                                "item.name": t.data.item[0].oss_buy_name,
                                "item.phone": t.data.item[0].oss_buy_phone,
                                price: t.data.go_real_price,
                                time: t.data.date,
                                code: t.data.go_code,
                                info: t.data.item,
                                data: t.data
                            });
                        }) : console.log(t);
                    });
                },
                fail: function(t) {
                    wx.hideLoading(), wx.showModal({
                        title: "提示",
                        content: "你取消了支付",
                        showCancel: !1,
                        success: function(t) {
                            o.setData({
                                stopClick: !1
                            });
                        }
                    });
                }
            });
        });
    },
    sureTap: function(t) {
        var o = t.currentTarget.dataset.orderid;
        a.userSureGoods({
            id: o,
            openid: e.globalData.openid
        }).then(function(t) {
            0 == t.errno ? (wx.showToast({
                title: t.message,
                icon: "success",
                duration: 1e3,
                success: function() {}
            }), wx.redirectTo({
                url: "../order/orderList?id=100"
            })) : wx.showToast({
                title: t.message,
                icon: "none",
                duration: 2e3
            });
        });
    },
    callTelphone: function(t) {
        if (console.log(t), "" == t.currentTarget.dataset.phone || void 0 == t.currentTarget.dataset.phone) return wx.showToast({
            title: "该团长暂无电话",
            icon: "loading",
            duration: 2e3
        }), !1;
        wx.makePhoneCall({
            phoneNumber: t.currentTarget.dataset.phone
        });
    },
    applyForService: function(t) {
        var a = t.currentTarget.dataset.id, e = t.currentTarget.dataset.gid, o = t.currentTarget.dataset.ossid;
        wx.navigateTo({
            url: "../refund/refundApply?id=" + a + "&gid=" + e + "&ossid=" + o
        });
    },
    toHome: function(t) {
        wx.reLaunch({
            url: "/pages/template/index"
        });
    },
    seeSend: function(t) {
        var a = t.currentTarget.dataset.orderid;
        wx.navigateTo({
            url: "/pages/order/orderExpress?id=" + a
        });
    },
    tocart: function(t) {
        wx.reLaunch({
            url: "/pages/template/cart"
        });
    },
    add: function(o) {
        var s = this, i = s.data.suggestGoods, n = o.currentTarget.dataset.id, d = {
            gid: n,
            num: 1,
            openid: e.globalData.openid
        };
        console.log(i);
        for (var r = 0; r < i.length; r++) {
            var c = "suggestGoods[" + r + "].curGoodsNum", g = s.data.suggestGoods[r].curGoodsNum, l = s.data.suggestGoods[r].g_limit_num, u = s.data.suggestGoods[r].num;
            u = parseInt(u), l = parseInt(l), g = parseInt(g);
            var p = Math.min(l, u);
            if (i[r].g_id == n) {
                if (console.log(g), g < p && l > 0) s.setData(t({}, c, g + 1)); else if (g < u && 0 == l) s.setData(t({}, c, g + 1)); else {
                    if (g >= l) return console.log(l, g), void wx.showToast({
                        title: "商品限购" + l + "件哦",
                        icon: "none",
                        duration: 2e3
                    });
                    if (g >= u) return void wx.showToast({
                        title: "商品数量没有那么多了",
                        icon: "none",
                        duration: 2e3
                    });
                }
                break;
            }
        }
        a.addCart(d).then(function(t) {
            console.log(t.data), 0 == t.errno ? (console.log(0), s.successtip(), wx.setStorageSync("cartnum", t.data.count), 
            s.setData({
                carnum: t.data.count
            }), 0 != t.data.count ? (wx.showTabBarRedDot({
                index: 2
            }), wx.setTabBarBadge({
                index: 2,
                text: t.data.count + ""
            })) : wx.hideTabBarRedDot({
                index: 2
            })) : wx.showToast({
                title: t.message,
                icon: "none",
                duration: 2e3
            });
        });
    },
    onCloseButton: function(t) {
        this.setData({
            specShow: !this.data.specShow
        });
    },
    addSpec: function(t) {
        console.log(t);
        var o = this, s = e.globalData.openid, i = t.currentTarget.dataset.id, n = t.currentTarget.dataset.atid;
        a.GetSpecInfo({
            openid: s,
            id: i
        }).then(function(t) {
            if (0 == t.errno) {
                var e = [], i = [];
                console.log(t.data.spec);
                for (var d in t.data.spec) {
                    var r = [], c = [];
                    i[d] = {
                        id: t.data.spec[d].id,
                        subSpec: t.data.spec[d].item[0].gsi_id
                    };
                    for (var g in t.data.spec[d].item) r[g] = t.data.spec[d].item[g].gsi_title, c[g] = t.data.spec[d].item[g].gsi_id;
                    e[d] = {
                        id: t.data.spec[d].id,
                        name: t.data.spec[d].title,
                        stem: r,
                        stem_id: c
                    };
                }
                for (var l = "", d = i.length - 1; d >= 0; d--) l += "," + i[d].subSpec;
                console.log(l, t.data.goods.g_id), a.GetSpecDeatail({
                    openid: s,
                    id_str: l,
                    gid: t.data.goods.g_id
                }).then(function(a) {
                    if (console.log(a), 0 == a.errno) {
                        var s = a.data.ggo_market_price.split("."), d = t.data.goods.g_limit_num <= 0 ? a.data.ggo_stock : parseInt(t.data.goods.g_limit_num) < parseInt(a.data.ggo_stock) ? t.data.goods.g_limit_num : a.data.ggo_stock, r = {
                            id: t.data.goods.g_id,
                            name: t.data.goods.g_name,
                            photo: t.data.goods.g_icon,
                            specInfo: a.data.ggo_title,
                            price: s,
                            oldPrice: a.data.ggo_old_price,
                            num: 1,
                            popup: e,
                            count: a.data.ggo_stock,
                            limit: d,
                            is_limit: t.data.goods.g_limit_num,
                            ggo_id: a.data.ggo_id
                        };
                        o.setData({
                            specDetail: r,
                            specShow: !o.data.specShow,
                            specDefault: i,
                            atid: n
                        });
                    } else wx.showToast({
                        title: t.message,
                        icon: "none"
                    });
                });
            } else wx.showToast({
                title: t.message,
                icon: "none"
            });
        });
    },
    specAddCart: function(o) {
        for (var s = this, i = o.currentTarget.dataset.id, n = o.currentTarget.dataset.optionid, d = o.currentTarget.dataset.num, r = o.currentTarget.dataset.atid, c = s.data.suggestGoods, g = 0; g < c.length; g++) {
            var l = "suggestGoods[" + g + "].curGoodsNum", u = s.data.suggestGoods[g].curGoodsNum;
            if (c[g].g_id == i) {
                if (!(0 == c[g].g_limit_num || u < c[g].g_limit_num)) return void wx.showToast({
                    title: "本商品限购" + c[g].g_limit_num + "件",
                    icon: "none",
                    duration: 2e3
                });
                s.setData(t({}, l, parseInt(u) + 1));
                break;
            }
        }
        a.SpecAddCart({
            openid: e.globalData.openid,
            gid: i,
            ggoid: n,
            num: d,
            at_id: r
        }).then(function(t) {
            0 == t.errno ? (s.successtip(), 0 != t.data.count ? (wx.showTabBarRedDot({
                index: 2
            }), wx.setTabBarBadge({
                index: 2,
                text: t.data.count + ""
            })) : wx.hideTabBarRedDot({
                index: 2
            }), s.setData({
                specShow: !1,
                carnum: t.data.count
            }), wx.setStorageSync({
                key: "cartnum",
                data: parseInt(t.data.count)
            })) : wx.showToast({
                title: t.message,
                icon: "none",
                duration: 2e3
            });
        });
    },
    popup: function(t) {
        for (var o = this, s = t.currentTarget.dataset.id, i = t.currentTarget.dataset.subid, n = o.data.specDefault, d = "", r = n.length - 1; r >= 0; r--) n[r].id == s && (n[r].subSpec = i, 
        o.setData({
            specDefault: n
        })), d += "," + n[r].subSpec;
        var c = e.globalData.openid, g = o.data.specDetail;
        a.GetSpecDeatail({
            openid: c,
            id_str: d,
            gid: g.id
        }).then(function(t) {
            if (0 == t.errno) {
                var a = t.data.ggo_market_price.split("."), e = g.is_limit <= 0 ? t.data.ggo_stock : parseInt(g.is_limit) < parseInt(t.data.ggo_stock) ? g.is_limit : t.data.ggo_stock;
                g.specInfo = t.data.ggo_title, g.price = a, g.oldPrice = t.data.ggo_old_price, g.count = t.data.ggo_stock, 
                g.limit = e, g.ggo_id = t.data.ggo_id, o.setData({
                    specDetail: g
                });
            } else wx.showToast({
                title: res.message,
                icon: "none"
            });
        });
    },
    onReachBottom: function(t) {
        console.log(t);
        var o = this;
        o.setData({
            "showlodingmore.showMore": !0,
            "showlodingmore.noMore": !1
        });
        var s = o.data.page;
        if (s < o.data.maxpage) {
            var i = {
                openid: e.globalData.openid,
                page: s + 1,
                gid: o.data.gids
            }, n = o.data.suggestGoods;
            console.log(i), a.GoodsInfoRecommend(i).then(function(t) {
                console.log(t);
                for (var a = 0; a < t.data.data.length; a++) n.push(t.data.data[a]);
                o.setData({
                    suggestGoods: n,
                    "showlodingmore.showMore": !1,
                    "showlodingmore.noMore": !1,
                    page: o.data.page + 1
                });
            });
        } else o.setData({
            "showlodingmore.showMore": !1,
            "showlodingmore.noMore": !1
        });
    },
    successtip: function() {
        arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
        var a = this;
        a.setData(t({}, "showSuccesstipInfo.showSuccesstip", !a.data.showSuccesstipInfo.showSuccesstip)), 
        console.log(a.data.showSuccesstipInfo.showSuccesstip), setTimeout(function() {
            a.setData(t({}, "showSuccesstipInfo.showSuccesstip", !a.data.showSuccesstipInfo.showSuccesstip));
        }, 1300);
    }
});